package se.vgregion.velocity.liferay.spring;

import com.liferay.portal.kernel.bean.BeanLocator;
import com.liferay.portal.kernel.bean.BeanLocatorException;
import org.springframework.stereotype.Component;

import java.util.Map;

public class VelocityBeanLocator implements BeanLocator {
 
    private static final String SUFFIX = ".velocity";
    
    public Object locate(String name) {
        String realName = stripVelocitySuffix(name);
        return SpringBeanLocator.getBean(realName);
    }
 
    private String stripVelocitySuffix(String name) {
        String realName = name;
        if (realName.endsWith(SUFFIX)) {
            realName = realName.substring(0, realName.length() - SUFFIX.length());
        }
        return realName;
    }
 
    public ClassLoader getClassLoader() {
        throw new UnsupportedOperationException();
    }
 
    public String[] getNames() {
        return new String[0];
    }
 
    public Class<?> getType(String name) throws BeanLocatorException {
        throw new UnsupportedOperationException();
    }
 
    public <T> Map<String, T> locate(Class<T> clazz) throws BeanLocatorException {
        throw new UnsupportedOperationException();
    }
}